<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$this->model('model')->checkvip();
if($_RQ['type']){
	$this->session('type',$_RQ['type']);
}
$type=$this->session('type');
if($_RQ['op']=='main'){
	$user=pdo_get('jy_kecheng_user',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	set_html('title','我的课程');
	$return['params']=array('type'=>$type?:'wechat','keyword'=>'');
	if($_RQ['keyword']){
		$return['params']['keyword']=$_RQ['keyword'];
	}
	$return['video_status']=$this->video_status;
	exi($return);
}
if($_RQ['op']=='getlist'){
	$return['params']=array();
	$params=array('ispay'=>1,'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']);
	if($_RQ['keyword']){
		$params2=array('uniacid'=>$_SESSION['uniacid']);
		$params2['title like']='%'.$_RQ['keyword'].'%';
		$return['params']['keyword']=$_RQ['keyword'];	
		$ids=pdo_getall('jy_kecheng_video',$params2,'id','id');
		if($ids){
			$ids=array_keys($ids);
			$params['video_id']=$ids;	
		}else{
			$params['video_id']=-1;
		}
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$list=pdo_getslice('jy_kecheng_video_order',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
	foreach($list as &$kv){
			$kv['thumb']=tomedia($kv['thumb']);
	}	
	//按点赞数排序作品
	if($list){
		$sum=count($list);
		foreach($list as &$item){
			$video=pdo_get('jy_kecheng_video',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['video_id']));
			$item=array_merge($video,$item);
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
			$item['thumb']=tomedia($item['thumb']);
			$item['likenum']=pdo_count('jy_kecheng_video_log',array('video_id'=>$item['video_id'],'uniacid'=>$_SESSION['uniacid'],'islike'=>1),'id');
			$quan_log=pdo_get('jy_kecheng_video_log',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'video_id'=>$item['video_id']));
			if($quan_log['id']){
				if($quan_log['isadd']==1){
					$item['islook']=2;
				}else{
					$item['islook']=1;
				}
			}
			
		}
	}
	$return['list']=$list;
	$return['params']['page'] =$pindex;
	exi($return);
}